$(function(){
	$('.detail_a_addlines').live('click',function(){
		$(this).parent().parent().next().next().hide();
		 $(this).parent().parent().next().slideToggle();
		 $(this).parent().parent().next().next().next().css('border-top','1px solid #dedede');
	});
	$('.facility_lines_a').live('click',function(){
		$(this).parent().parent().next().hide();
		 $(this).parent().parent().next().next().slideToggle();
		 $(this).parent().parent().next().next().next().css('border-top','1px solid #dedede');
	});
	$('.pwsj_right_byq_divbox .add_facility_box img').live('click',function(){
		$(this).parent().slideToggle();
		$(this).parent().next().next().css('border-top','none');
	});
	$('.pwsj_right_byq_divbox .add_lines_box img').live('click',function(){
		$(this).parent().slideToggle();
		$(this).parent().next().css('border-top','none');
	});
	
	goToPage(1);
});
function goToPage(pageNo){
	var deviceName = $('#deviceName').val();
	$.ajax({
		url : contextPath + 'user/dyxl/list',
		data : {
			deviceType : pdtype,
			transformerCode : pdid,
			deviceName : deviceName,
			pageNo : pageNo,
			pageSize : 10
		},
		type : 'POST',
		success : function(list) {
			$(".pwsj_right_byq_divbox").empty();
			$(".page").empty();
			if(list!=null && list.totalRecord>0){
				var obj = list.records;
				for(var i=0;i<obj.length;i++){
					var div= '<ul class="byq_cont_ul">';
					div += '<li id="deviceBox" name="deviceBox" class="" style="width:4%;"><input type="checkbox" value="'+obj[i].deviceid+'" class="checkbox" /></li>';
					div += '<li style="width:25%;"><a href="dyxlinfo.jsp?deviceid='+obj[i].deviceid+'&pdtype='+pdtype+'&pdid='+obj[i].transformercode+'">'+(obj[i].devicename==null?"":obj[i].devicename)+'</a></li>';
					div += '<li style="width:22%;">'+(obj[i].note==null?"":obj[i].note)+'</li>';
					div += '<li style="width:10%;">'+(obj[i].operationstate==null?"":obj[i].operationstate)+'</li>';
					div += '<li style="width:10%;">'+(obj[i].linetype==null?"":obj[i].linetype)+'</li>';
					div += '<li class="operate" style="width:28%; border-right:none;">';
					//权限判断
					/*if(true){
						div +=	'<a  class="detail_a">编辑</a>';
					}*/
					if(lowaddaction){
						div +=	'<a  class="detail_a_addlines">新增列表</a>';
					}
					if(true){
						div +=	'<a  class="facility_lines_a">设备列表</a>';
					}
					
					
					if(loweditaction){
						div += '<a href="'+contextPath+'user/d/dyxledite.jsp?deviceid='+obj[i].deviceid+'" class="detail_a_edite">编辑</a>';
					}
					if(lowdeleteaction){
						div += '<a  class="detail_a_del" onclick="devicedel(\'dyxl\',\''+obj[i].deviceid+'\',0,0)">删除</a>';
					}
                    div += '<a  class="detail_a_del" onclick="exportExcel111(\''+obj[i].devicename+'\',\''+obj[i].deviceid+'\')">导出</a>';
					div +=	'</li>';
					div += '</ul>';
					div += '<div class="add_facility_box" style="display:none;">';
					div += '<a href="'+contextPath+'user/d/dygtadd.jsp?deviceid='+obj[i].deviceid+'" class="add_facility_btn">新增杆塔</a>';
					div += '<a href="'+contextPath+'user/d/dydxadd.jsp?deviceid='+obj[i].deviceid+'" class="add_facility_btn">新增导线</a>';
					div += '<a href="'+contextPath+'user/d/dysydlbhqadd.jsp?deviceid='+obj[i].deviceid+'" class="add_facility_btn">新增剩余电流保护器</a>';
					div += '<a href="'+contextPath+'user/d/dybxadd.jsp?deviceid='+obj[i].deviceid+'" class="add_facility_btn">新增表箱</a>';
					div += '<a href="'+contextPath+'user/d/dyjckyadd.jsp?deviceid='+obj[i].deviceid+'" class="add_facility_btn">新增交叉跨越</a>';
					div += '<a href="'+contextPath+'user/d/dypdxadd.jsp?deviceid='+obj[i].deviceid+'" class="add_facility_btn">新增配电箱</a>';
					div += '<a href="'+contextPath+'user/d/dydladd.jsp?deviceid='+obj[i].deviceid+'" class="add_facility_btn">新增电缆</a>';
					div += '<a href="'+contextPath+'user/d/dydlfjxadd.jsp?deviceid='+obj[i].deviceid+'" class="add_facility_btn">新增电缆分接箱</a>';
					div += '<a href="'+contextPath+'user/d/dyyhjrdadd.jsp?deviceid='+obj[i].deviceid+'" class="add_facility_btn">新增用户接入点</a>';
					div += '<img src="../images/add_facility_close.png" alt="" /></div>';
					div += '<div class="add_lines_box" style="display:none;">';
					div += '<a href="'+contextPath+'user/d/dygtlist.jsp?deviceid='+obj[i].deviceid+'" class="add_lines_btn">杆塔列表</a>';
					div += '<a href="'+contextPath+'user/d/dysydlbhqlist.jsp?deviceid='+obj[i].deviceid+'" class="add_lines_btn">剩余电流保护器列表</a>';
					div += '<a href="'+contextPath+'user/d/dybxlist.jsp?deviceid='+obj[i].deviceid+'" class="add_lines_btn">表箱列表</a>';
					div += '<a href="'+contextPath+'user/d/dydxlist.jsp?deviceid='+obj[i].deviceid+'" class="add_lines_btn">导线列表</a>';
					div += '<a href="'+contextPath+'user/d/dypdxlist.jsp?deviceid='+obj[i].deviceid+'" class="add_lines_btn">配电箱列表</a>';
					div += '<a href="'+contextPath+'user/d/dydlfjxlist.jsp?deviceid='+obj[i].deviceid+'" class="add_lines_btn">分接箱列表</a>';
					div += '<a href="'+contextPath+'user/d/dydllist.jsp?deviceid='+obj[i].deviceid+'" class="add_lines_btn">电缆列表</a>';
					div += '<a href="'+contextPath+'user/d/dyyhjrdlist.jsp?deviceid='+obj[i].deviceid+'" class="add_lines_btn">用户接入点列表</a>';
					div += '<a href="'+contextPath+'user/d/dyjckylist.jsp?deviceid='+obj[i].deviceid+'" class="add_lines_btn">交叉跨越列表</a>';
					div += '<img src="../images/add_facility_close.png" alt="" /></div>';
					$(".pwsj_right_byq_divbox").append(div);
				}
				pageList(list);
			}
		}
	});
}
function exportExcel111(devicename,deviceId){
    var templateId = 3;
    if(confirm("确定导出对应PMS模板数据吗？")){
        $("#exportimg").show();
        $.ajax({
            url : contextPath+ 'user/excel/exportDYPMS',
            data : {
                devicename : devicename,
                templateId : templateId,
                deviceId : deviceId
            },
            type : 'POST',
            success : function(data) {
                //alert(data.msgDesc);
                $("#exportimg").hide();
                if(data.msgDesc=="导出失败"){
                    alert(data.msgDesc);
                }else if(data.msgDesc=="none"){
                    alert("导出失败");
                }else{
                    var downloadurl=contextPath+ 'user/excel/download?filename='+data.msgDesc;
                    //alert(uploadurl);
                    window.location.href =downloadurl;
                }
            }
        });
    }
}